package top.codetheory.thread._001_打断;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class _002_测试打断阻塞线程 {
    /**
     * 会有异常的原因就是在尝试打断一个block的线程， 所以会有异常， 这时候<br>
     * <img src="https://gitee.com/codetheory/img-on1/raw/master/img01/1714519064553-2024-5-107:17:45.png"  />
     */
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.info("打断状态: {}", Thread.currentThread().isInterrupted());  // 会一直输出这行代码, 说明打断阻塞线程后, 被打断线程还会一直运行
            }
        }, "t1");
        t1.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        t1.interrupt();

        log.info("main end");

    }
}